import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'


Vue.use(VueRouter)

const routes = [
 {
  path:'/login',component:()=>import('../views/login.vue')
 },
 {
  path:'/',component:()=>import('../views/index.vue'),
  redirect:'/dashboard',
  children:[
    {
      path:'dashboard',component:()=>import('../views/dashboard.vue')
    },
    {
      path:'article',component:()=>import('../views/artical/artical.vue')
    }
  ]
 }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to,from,next)=>{

  if(to.path==='/login'){
    next()
    return
  }
  if(store.state.user.tokenn){
    next()
    return
  }
  next('/login')

})

export default router
